#include "XORByteArray.h"

namespace miniprojeto {
namespace util {

XORByteArray::XORByteArray(int arrayLen) {
	this->arrayLen = arrayLen;
	arrays = new vector<unsigned char*>();
	arrayCount = 0;
}

XORByteArray::~XORByteArray() {
	delete arrays;
}

void XORByteArray::addByteArray(unsigned char nArray[]) {
	if (nArray != NULL) {
		arrays->push_back(nArray);
		arrayCount++;
	}
	
}

unsigned char* XORByteArray::evaluateXor() {
	if (arrayCount == 0) {
		return NULL;
	}
	unsigned char* ret = new unsigned char[arrayLen];
	
	for (int i = 0; i <arrayLen; i++) {
		unsigned char aux;
		aux = (*arrays)[0][i];
		for (int j = 1; j < arrayCount; j++) {
			 aux = aux ^ (*arrays)[j][i];
		}
		ret[i] = aux;
	}
	return ret;
}

}
}

